﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Serenity.Libra.Web.ViewModels;
using OSharp.Utility.Logging;
using OSharp.Web.Mvc.Security;

namespace Serenity.Libra.Web.Controllers
{
    public class HomeController : Controller
    {
        private static readonly ILogger Logger = LogManager.GetLogger(typeof(HomeController));

        #region Ajax功能

        #region 获取数据

        [AjaxOnly]
        [Description("管理-菜单数据")]
        public ActionResult GetMenuData()
        {
            List<MiniUINode> nodes = new List<MiniUINode>()
            {
                //new MiniUINode()
                //{
                //    text = "权限设置",
                //    iconCls = "pic_26",
                //    children = new List<MiniUINode>()
                //    {
                //        new MiniUINode() { text = "用户管理", iconCls = "pic_5", url = Url.Action("Index", "Users") },
                //        new MiniUINode() { text = "角色管理", iconCls = "pic_198", url = Url.Action("Index", "Roles") },
                //        //new MiniUINode() { text = "组织机构管理", iconCls = "pic_93", url = Url.Action("Index", "Organizations") },
                //        //new MiniUINode() { text = "功能管理", iconCls = "pic_94", url = Url.Action("Index", "Functions") },
                //        //new MiniUINode() { text = "实体数据管理", iconCls = "pic_95", url = Url.Action("Index", "EntityInfos") },
                //    }
                //},
                new MiniUINode()
                {
                    text = "系统设置",
                    iconCls = "icon-folderopen",
                    children = new List<MiniUINode>()
                    {
                        new MiniUINode() { text = "字典管理", iconCls = "icon-folder", url = Url.Action("Index", "DictItem") },
                        new MiniUINode() { text = "操作日志", iconCls = "icon-folder", url = Url.Action("OperateLogs", "Logging") },
                    }
                }
            };

            Action<ICollection<MiniUINode>> action = list =>
            {
                foreach (MiniUINode node in list)
                {
                    node.id = "node" + node.text;
                }
            };

            foreach (MiniUINode node in nodes)
            {
                node.id = "node" + node.text;
                if (node.children != null && node.children.Count > 0)
                {
                    action(node.children);
                }
            }

            return Json(nodes, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #endregion
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }

        [Description("管理-欢迎页")]
        public ActionResult Welcome()
        {
            return View();
        }
    }
}